<template>
	<view class="settings-container">
		<!-- 设置列表 -->
		<view class="settings-list">
			<view class="settings-item" @click="goToFeedback">
				<text class="item-text">意见反馈</text>
				<text class="iconfont icon-right"></text>
			</view>
			<!-- 其他设置项可以放在这里 -->
		</view>
		
		<!-- 底部按钮区域 -->
		<view class="bottom-buttons">
			<view class="btn" @click="switchAccount">
				<text>切换账号</text>
			</view>
			<view class="btn logout-btn" @click="handleLogout">
				<text>退出登录</text>
			</view>
		</view>
	</view>
</template>

<script>
	import { mapActions } from 'vuex'
	import { logout } from '@/api/user'
	
	export default {
		methods: {
			// 跳转到意见反馈页面
			goToFeedback() {
				uni.navigateTo({
					url: '/pages/feedback/index'
				})
			},
			// 切换账号
			switchAccount() {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			},
			// 退出登录
			async handleLogout() {
				uni.showModal({
					title: '提示',
					content: '确定要退出登录吗？',
					success: async (res) => {
						if (res.confirm) {
							try {
								// 调用退出接口
								await logout()
							} catch (error) {
								console.error('退出失败:', error)
							}
							// 无论接口是否成功，彻底清理本地缓存和状态
							this.$store.commit('user/SET_USER_INFO', {})
							this.$store.commit('user/SET_TOKEN', '')
							uni.removeStorageSync('token')
							uni.removeStorageSync('userInfo')
							uni.removeStorageSync('isLogin')
							// 跳转到登录页
							uni.reLaunch({
								url: '/pages/login/login',
								success: () => {
									setTimeout(() => {
										uni.showToast({
											title: '退出成功',
											icon: 'success'
										})
									}, 200)
								}
							})
						}
					}
				})
			}
		}
	}
</script>

<style>
	.settings-container {
		min-height: 100vh;
		background-color: #f8f8f8;
		padding: 20rpx;
		padding-bottom: 180rpx;
		box-sizing: border-box;
	}
	
	.settings-list {
		background-color: #fff;
		border-radius: 12rpx;
		overflow: hidden;
	}
	
	/* 底部按钮样式 */
	.bottom-buttons {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 20rpx;
		background-color: #fff;
		box-shadow: 0 -2rpx 6rpx rgba(0, 0, 0, 0.05);
	}
	
	.btn {
		width: 90%;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		border-radius: 40rpx;
		margin-bottom: 20rpx;
		font-size: 28rpx;
		background-color: #fff;
		border: 1rpx solid #ddd;
		color: #333;
	}
	
	.logout-btn {
		background-color: #f56c6c;
		color: #fff;
		border: none;
	}
	
	.btn text {
		display: inline-block;
		width: 100%;
		text-align: center;
	}
	
	.settings-item {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 30rpx;
		border-bottom: 1rpx solid #f5f5f5;
	}
	
	.item-text {
		font-size: 28rpx;
		color: #333;
	}
	
	.icon-right {
		font-size: 24rpx;
		color: #999;
	}
</style> 